package com.sandking.db.dao;

import javax.sql.DataSource;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.QueryRunner;
import com.sandking.config.SK_Config;
import java.sql.Connection;
import com.sandking.metadata.jdbc.SK_Query;
import java.util.Map;
import com.sandking.db.bean.Yhxl;
import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.handlers.MapListHandler;

public class YhxlDao {
	public static Yhxl insert(Yhxl yhxl){
		Connection conn = SK_Config.getConnection();
		return insert(yhxl,conn);
	}
	
	public static Yhxl insert(Yhxl yhxl,Connection conn){
		return insert(yhxl,conn,Yhxl.TABLENAME);
	}
	
	public static Yhxl insert(Yhxl yhxl,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insert(yhxl,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhxl insert(Yhxl yhxl,String tableName){
		Connection conn = SK_Config.getConnection();
		return insert(yhxl,conn,tableName);
	}
	
	public static Yhxl insert(Yhxl yhxl,Connection conn,String tableName){
		
		SK_Query sq = new SK_Query();
		String sql = "INSERT INTO " +tableName+ " (id,修炼id,是否有效,用户_id) VALUES (?,?,?,?)";
		try {
			int i = (int)sq.insert(conn,sql,yhxl.getId(),yhxl.getXlid(),yhxl.getSfyx(),yhxl.getYh_id());
			if(yhxl.getId()==0){
				yhxl.setId(i);
			}
			return i > 0 ? yhxl : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Yhxl insert(Yhxl yhxl,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insert(yhxl,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls){
		Connection conn = SK_Config.getConnection();
		return insertBatch(yhxls,conn);
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls,Connection conn){
		return insertBatch(yhxls,conn,Yhxl.TABLENAME);
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(yhxls,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls,String tableName){
		Connection conn = SK_Config.getConnection();
		return insertBatch(yhxls,conn,tableName);
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "INSERT INTO " +tableName+ " (id,修炼id,是否有效,用户_id) VALUES (?,?,?,?)";
		try {
			int columnSize = 4;
			int size = yhxls.size();
			Object[][] params = new Object[size][columnSize];
			for (int i = 0; i < size; i++) {
				params[i][0] =yhxls.get(i).getId();
				params[i][1] =yhxls.get(i).getXlid();
				params[i][2] =yhxls.get(i).getSfyx();
				params[i][3] =yhxls.get(i).getYh_id();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] insertBatch(List<Yhxl> yhxls,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(yhxls,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static Yhxl update(Yhxl yhxl){
		Connection conn = SK_Config.getConnection();
		return update(yhxl,conn);
	}
	
	public static Yhxl update(Yhxl yhxl,Connection conn){
		return update(yhxl,conn,Yhxl.TABLENAME);
	}
	
	public static Yhxl update(Yhxl yhxl,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return update(yhxl,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhxl update(Yhxl yhxl,String tableName){
		Connection conn = SK_Config.getConnection();
		return update(yhxl,conn,tableName);
	}
	
	public static Yhxl update(Yhxl yhxl,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		StringBuffer sb = new StringBuffer();
		Map<String, Object> updateColumns = yhxl.getUpdateColumns();
		int columnSize = updateColumns.size();
		if (updateColumns.isEmpty()) {
			return yhxl;
		}
		sb.append("UPDATE ");
		sb.append(tableName);
		sb.append(" SET ");
		Object[] values = new Object[(columnSize + 1)];
		int i = 0;
		for (Map.Entry<String, Object> updateColumn : updateColumns.entrySet()) {
			String key = updateColumn.getKey();
			values[i] = updateColumn.getValue();
			i++;
			sb.append(key);
			sb.append("=");
			sb.append("?");
			if (i < columnSize) {
				sb.append(",");
			}
		}
		sb.append(" WHERE ");
		sb.append("id");
		sb.append(" = ?");
		values[columnSize] = yhxl.getId();
		String sql = sb.toString();
		try {
			i = run.update(conn, sql, values);			
			return i == 1 ? yhxl : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally {
			try{
				yhxl.clearUpdateColumn();
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Yhxl update(Yhxl yhxl,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return update(yhxl,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls){
		Connection conn = SK_Config.getConnection();
		return updateBatch(yhxls,conn);
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls,Connection conn){
		return updateBatch(yhxls,conn,Yhxl.TABLENAME);
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(yhxls,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls,String tableName){
		Connection conn = SK_Config.getConnection();
		return updateBatch(yhxls,conn,tableName);
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "UPDATE " +tableName+ " SET id = ?,修炼id = ?,是否有效 = ?,用户_id = ? WHERE id = ?";
		try {
			int columnSize = 4;
			int size = yhxls.size();
			Object[][] params = new Object[size][columnSize + 1];
			for (int i = 0; i < size; i++) {
				params[i][0] =yhxls.get(i).getId();
				params[i][1] =yhxls.get(i).getXlid();
				params[i][2] =yhxls.get(i).getSfyx();
				params[i][3] =yhxls.get(i).getYh_id();
				params[i][columnSize] =yhxls.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] updateBatch(List<Yhxl> yhxls,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(yhxls,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static boolean delete(Yhxl yhxl){
		Connection conn = SK_Config.getConnection();
		return delete(yhxl,conn);
	}
	
	public static boolean delete(Yhxl yhxl,Connection conn){
		return delete(yhxl,conn,Yhxl.TABLENAME);
	}
	
	public static boolean delete(Yhxl yhxl,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return delete(yhxl,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean delete(Yhxl yhxl,String tableName){
		Connection conn = SK_Config.getConnection();
		return delete(yhxl,conn,tableName);
	}
	
	public static boolean delete(Yhxl yhxl,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int i = run.update(conn,sql, yhxl.getId());
			return i > 0 ? true : false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean delete(Yhxl yhxl,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return delete(yhxl,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	
	public static boolean deleteBatch(List<Yhxl> yhxls){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(yhxls,conn);
	}
	
	public static boolean deleteBatch(List<Yhxl> yhxls,Connection conn){
		return deleteBatch(yhxls,conn,Yhxl.TABLENAME);
	}
	
	public static boolean deleteBatch(List<Yhxl> yhxls,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(yhxls,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteBatch(List<Yhxl> yhxls,String tableName){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(yhxls,conn,tableName);
	}
	
	public static boolean deleteBatch(List<Yhxl> yhxls,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int size = yhxls.size();
			Object[][] params = new Object[size][1];
			for (int i = 0; i < size; i++) {
				params[i][0] = yhxls.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean deleteBatch(List<Yhxl> yhxls,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(yhxls,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 根据( id ) 查询
	 */
	public static Yhxl getById(int id){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn);
	}
	
	public static Yhxl getById(int id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn,tableName);
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhxl> getByYh_id(int yh_id){
		Connection conn = SK_Config.getConnection();
		return getByYh_id(yh_id, conn);
	}
	
	public static List<Yhxl> getByYh_id(int yh_id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByYh_id(yh_id, conn,tableName);
	}
	
	public static List<Yhxl> getByPageYh_id(int yh_id,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageYh_id(yh_id, conn,page,pageCount);
	}
	
	public static List<Yhxl> getByPageYh_id(int yh_id,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageYh_id(yh_id, conn,tableName,page,pageCount);
	}
	/**
	 * 根据( 是否有效  用户_id ) 查询
	 */
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id){
		Connection conn = SK_Config.getConnection();
		return getBySfyxYh_id(sfyx, yh_id, conn);
	}
	
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getBySfyxYh_id(sfyx, yh_id, conn,tableName);
	}
	
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageSfyxYh_id(sfyx, yh_id, conn,page,pageCount);
	}
	
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageSfyxYh_id(sfyx, yh_id, conn,tableName,page,pageCount);
	}
	
	//Connection
	/**
	 * 根据( id ) 查询
	 */
	public static Yhxl getById(int id,Connection conn){
		return getById(id,conn,Yhxl.TABLENAME);
	}
	
	public static Yhxl getById(int id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " WHERE " + "id = ?";
		Yhxl yhxl = null; 
		try {
			Map<String, Object> map = run.query(conn,sql, new MapHandler(), id);
			yhxl = Yhxl.createForColumnNameMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxl;
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhxl> getByYh_id(int yh_id,Connection conn){
		return getByYh_id(yh_id,conn,Yhxl.TABLENAME);
	}
	
	public static List<Yhxl> getByYh_id(int yh_id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " WHERE " + "yh_id = ?";
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), yh_id);
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Yhxl> getByPageYh_id(int yh_id,Connection conn,int page,int pageCount){
		return getByPageYh_id(yh_id,conn,Yhxl.TABLENAME,page,pageCount);
	}
	
	public static List<Yhxl> getByPageYh_id(int yh_id,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " WHERE " + "yh_id = ? LIMIT " + page + " , " +pageCount;
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), yh_id);
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	/**
	 * 根据( 是否有效  用户_id ) 查询
	 */
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id,Connection conn){
		return getBySfyxYh_id(sfyx, yh_id,conn,Yhxl.TABLENAME);
	}
	
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " WHERE " + "sfyx = ? AND yh_id = ?";
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), sfyx, yh_id);
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,Connection conn,int page,int pageCount){
		return getByPageSfyxYh_id(sfyx, yh_id,conn,Yhxl.TABLENAME,page,pageCount);
	}
	
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " WHERE " + "sfyx = ? AND yh_id = ? LIMIT " + page + " , " +pageCount;
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), sfyx, yh_id);
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	
	//DataSource
	/**
	 * 根据( id ) 查询
	 */
	public static Yhxl getById(int id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhxl getById(int id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhxl> getByYh_id(int yh_id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByYh_id(yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getByYh_id(int yh_id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByYh_id(yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Yhxl> getByPageYh_id(int yh_id,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageYh_id(yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getByPageYh_id(int yh_id,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageYh_id(yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 根据( 是否有效  用户_id ) 查询
	 */
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getBySfyxYh_id(sfyx, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getBySfyxYh_id(boolean sfyx, int yh_id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getBySfyxYh_id(sfyx, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageSfyxYh_id(sfyx, yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getByPageSfyxYh_id(boolean sfyx, int yh_id,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageSfyxYh_id(sfyx, yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public static List<Yhxl> getAll(){
		Connection conn = SK_Config.getConnection();
		return getAll(conn);
	}
	
	public static List<Yhxl> getAll(Connection conn){
		return getAll(conn,Yhxl.TABLENAME);
	}
	
	public static List<Yhxl> getAll(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getAll(String tableName){
		Connection conn = SK_Config.getConnection();
		return getAll(conn,tableName);
	}
	
	public static List<Yhxl> getAll(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName;
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	
	public static List<Yhxl> getAll(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static List<Yhxl> getAllPage(int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,page,pageCount);
	}
	
	public static List<Yhxl> getAllPage(Connection conn,int page,int pageCount){
		return getAllPage(conn,Yhxl.TABLENAME,page,pageCount);
	}
	
	public static List<Yhxl> getAllPage(DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhxl> getAllPage(String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,tableName,page,pageCount);
	}
	
	public static List<Yhxl> getAllPage(Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,修炼id,是否有效,用户_id FROM " + tableName + " LIMIT " + page + " , " +pageCount;
		List<Yhxl> yhxls = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			yhxls = Yhxl.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhxls;
	}
	
	public static List<Yhxl> getAllPage(DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,tableName,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
}